package Bean;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 *
 * @author 黄忠
 */

@SuppressWarnings("unused")
public class SqlBean {
    protected Connection con=null;
    protected Statement stmt=null;
    protected ResultSet rs=null;

    public boolean connectSQL(){
        try {
            Class.forName("org.h2.Driver");
            String url="jdbc:h2:~/eazenSQL";
            con= DriverManager.getConnection(url,"eazen","201741412126");
            stmt=con.createStatement();
            return true;
        }
        catch (Exception e){
            e.printStackTrace();
        }
        return false;
    }

    public boolean closeSQL(){
        try {
            rs.close();
            stmt.close();
            con.close();
            return true;
        }
        catch (Exception e){
            e.printStackTrace();
        }
        return false;
    }

    public ResultSet executeQuery(String sql){
        try {
            rs=stmt.executeQuery(sql);
        }
        catch (Exception e){
            e.printStackTrace();
        }
        return rs;
    }

    public void executeUpdate(String sql){
        try {
            stmt.executeUpdate(sql);
        }
        catch (Exception e){
            e.printStackTrace();
        }
    }
}
